import request from '@/config/axios'

export interface Rule {
  // 接口传参
  browseRuleId?: number
  buyRuleId?: number
}

export interface BrowseRule {
  // 接口传参
  browseRuleId?: number | number[]

  browseRule: EmptyArrayType
  browseMember: EmptyArrayType //浏览权限 会员
  browsePaidmember: EmptyArrayType //浏览权限 付费会员
  browseTags: EmptyArrayType //浏览权限 标签组
}
export interface BuyRule {
  // 接口传参
  buyRuleId?: number | number[]

  buyRule: EmptyArrayType
  buyMember: EmptyArrayType //浏览权限 会员
  buyPaidmember: EmptyArrayType //浏览权限 付费会员
  buyTags: EmptyArrayType //浏览权限 标签组
}

// 获得 Spu 列表
export const getSpuPage = (params: PageParam) => {
  return request.get({ url: '/product/spu/page', params })
}

// 获得 Spu 列表 tabsCount
export const getTabsCount = (params: { spuType: string }) => {
  return request.get({ url: '/product/spu/get-count', params })
}

// 创建商品 Spu
export const createSpu = (data: Spu) => {
  return request.post({ url: '/product/spu/create', data })
}

// 更新商品 Spu
export const updateSpu = (data: Spu) => {
  return request.put({ url: '/product/spu/update', data })
}

// 更新商品 Spu status
export const updateStatus = (data: { spuId: number; status: number }) => {
  return request.put({ url: '/product/spu/update-status', data })
}

// 获得商品 Spu
export const getSpu = (spuId: number) => {
  return request.get({ url: `/product/spu/get-detail?spuId=${spuId}` })
}

// 获得商品 Spu 详情列表
export const getSpuDetailList = (ids: number[]) => {
  return request.get({ url: `/product/spu/list?spuIds=${ids}` })
}

// 删除商品 Spu
export const deleteSpu = (spuId: number) => {
  return request.delete({ url: `/product/spu/delete?spuId=${spuId}` })
}

// 导出商品 Spu Excel
export const exportSpu = async (params) => {
  return await request.download({ url: '/product/spu/export', params })
}

// 获得商品 SPU 精简列表
export const getSpuSimpleList = async () => {
  return request.get({ url: '/product/spu/list-all-simple' })
}
